package com.gj.costprice.controller;

import com.yyq.costprice.model.CostPriceAddVo;
import com.yyq.costprice.model.CostPriceSelectVo;
import com.yyq.costprice.model.SparePartVo;
import com.yyq.costprice.service.CostPriceService;
import com.yyq.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by Administrator on 2021-06-24.
 */
@RestController
@CrossOrigin
public class CostPriceController {

    @Autowired
    private CostPriceService costPriceService;

    @PostMapping("/materialCostPrice/queryPage")
    //一、分页查询接口
    public ResultVo queryPage(@RequestBody @Valid CostPriceSelectVo costPriceSelectVo, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            bindingResult.getFieldError().getDefaultMessage();
        }
        ResultVo  resultVo = costPriceService.queryPage(costPriceSelectVo);
        return resultVo;
    }



    @PostMapping("/materialCostPrice/add")
    //二、新增接口
    /* {"sparecode":"0001", "pageIndex":0, "pageSize":10}*/
    public ResultVo add(@RequestBody @Valid CostPriceAddVo costPriceAddVo, BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            bindingResult.getFieldError().getDefaultMessage();
        }
        ResultVo  resultVo = costPriceService.add(costPriceAddVo);
        return resultVo;
    }




    @GetMapping("/materialCostPrice/queryPlantListByLegalPersonCode")
    //三、根据法人编码得到工厂信息
    public ResultVo queryPlantListByLegalPersonCode( String legalPersonCode){

        ResultVo  resultVo = costPriceService.queryPlantListByLegalPersonCode(legalPersonCode);
        return resultVo;
    }



    @PostMapping("/metadata/getPullDownList")
    //四、价格分类、币别、当前状态下拉列表三个下拉框
    public ResultVo getPullDownList( ){

        ResultVo  resultVo = costPriceService.getPullDownList();
        return resultVo;
    }



    @GetMapping("/materialCostPrice/queryAllTaxType")
    //五、查询含税类型接口
    public ResultVo queryAllTaxType( ){
        ResultVo  resultVo = costPriceService.queryAllTaxType();
        return  resultVo;
    }



    @PostMapping("/material/searchEnabled")
    //六、选择备件弹窗接口
    public ResultVo searchEnabled(@RequestBody @Valid SparePartVo sparePartVo,BindingResult bindingResult){
        if(bindingResult.hasErrors()){
            bindingResult.getFieldError().getDefaultMessage();
        }
        ResultVo  resultVo = costPriceService.searchEnabled(sparePartVo);
        return resultVo;
    }


}
